﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameDataLibrary;

namespace UtopianGame
{
    public class Policy
    {
        public PolicyData xmlData;

        public Policy(PolicyData newXMLData)
        {
            xmlData = newXMLData;
        }

        public void implement()
        {
            if (Nation.moneyInTreasury >= xmlData.implementationCost || xmlData.implementationCost <= 0)
            {
                Nation.moneyInTreasury -= xmlData.implementationCost;
                StatusEffect statusEffectToAdd = null;
                //find the status effect to add to the Nation.
                for(int i=0;i<GlobalDataHolder.statusEffectArray.Length;i++)
                {
                    if(GlobalDataHolder.statusEffectArray[i].xmlData.name == xmlData.statusEffectName)
                    {
                        statusEffectToAdd = GlobalDataHolder.statusEffectArray[i];
                    }
                }
                Nation.statusEffectList.Add(statusEffectToAdd);
                //If necessary, add the status effect to the selected region.
                if (xmlData.isRegionSpecific)
                {
                    statusEffectToAdd.regionNumber = GlobalDataHolder.currentlySelectedRegion;
                }
                //Find the policy that's equal to this one.
                for (int i = 0; i < Nation.policyList.Count; i++)
                {
                    if (Nation.policyList[i].xmlData == this.xmlData)
                    {
                        //Remove it from this turn's choices.
                        Nation.policyList.RemoveAt(i);
                    }
                }

            }
        }
    }
}
